package com.smartboot.plus.dto;


import com.alibaba.fastjson2.annotation.JSONField;
import com.smartboot.plus.enums.MqttMetricEnum;

import java.util.Date;
import java.util.concurrent.atomic.LongAdder;



public class MetricItemDTO {
	private String code;
	private String desc;

	private final LongAdder metric;
	private long latestValue;
	private final int period;
	@JSONField(
		format = "yyyy-MM-dd HH:mm:ss"
	)
	private Date time;
	private Date created;

	public MetricItemDTO() {
		this.metric = new LongAdder();
		this.period = 0;
		this.created = new Date();
	}

	public MetricItemDTO(MqttMetricEnum metricEnum) {
		this(metricEnum, 0);
	}

	public MetricItemDTO(MqttMetricEnum metricEnum, int period) {
		this.metric = new LongAdder();
		this.code = metricEnum.getCode();
		this.desc = metricEnum.getDesc();
		this.period = period;
		this.created = new Date();
	}

	public String getCode() {
		return this.code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getDesc() {
		return this.desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public long getValue() {
		return this.metric.longValue();
	}

	public void setValue(long value) {
		this.metric.reset();
		this.metric.add(value);
	}

	public LongAdder getMetric() {
		return this.metric;
	}

	public int getPeriod() {
		return this.period;
	}

	public Date getTime() {
		return this.time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public long getLatestValue() {
		return this.latestValue;
	}

	public void setLatestValue(long latestValue) {
		this.latestValue = latestValue;
	}

	public Date getCreated() {
		return this.created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}
}
